package com.chisheng.caa.pojo.dto;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.chisheng.caa.service.MajorService;
import com.chisheng.caa.util.BeanUtil;
import com.chisheng.caa.validator.Contains;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

import static com.chisheng.caa.config.CaaConfig.MAX_YEAR;
import static com.chisheng.caa.config.CaaConfig.MIN_YEAR;

@Data
@NoArgsConstructor
@ApiModel("年级信息数据传输类")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GradeDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotNull(message = "{ArrangementSetting.arrangementYear.message}")
    @ApiModelProperty("年级年份")
    @Min(value = MIN_YEAR, message = "{ArrangementSetting.arrangementYear.message}")
    @Max(value = MAX_YEAR, message = "{ArrangementSetting.arrangementYear.message}")
    private Integer enrollmentYear;

    @NotNull(message = "{ArrangementSetting.majorName.message}")
    @ApiModelProperty("专业名称")
    @Contains(beanClass = MajorService.class, methodName = "getMajorNameList", message = "{ArrangementSetting.majorName.message}")
    private String majorName;

    @SuppressWarnings("all")
    public GradeDTO(GradeDTO grade) {
        BeanUtil.copyProperties(grade, this, true);
    }

    /**
     * 返回年级信息是否为空。专业名称为空且年级年份为 null 时返回 true。
     */
    @JsonIgnore
    public boolean isEmpty() {
        return StrUtil.isEmpty(majorName) || ObjectUtil.isNull(enrollmentYear);
    }

}
